<template>
	<view>
		<view class="padding" style="background-color: #FFFFFF; margin-top: 2%;">
			<view v-if="!login" @click="gologin" style="text-align: center;">现在是未登录状态，点击进行登录</view>
			<view v-else style="display: flex;align-items: center;">
				<view class="cu-avatar round" style="background-image:url
			 (https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg);margin-left: 3upx;
			 display: none;">
				</view>
				<view class="listcard-header_image cu-avatar lg">
					<image :src="info.atr"></image>
				</view>
				<view style="margin-left: 5%;">用户名：{{info.phone||info.name}}</view>
			</view>
		</view>
		<view class=" list " v-if="login">
			<view class="cuIcon-comment" @click="message">
				<text>消息通知 </text>
				<view v-if="msgnum" class="cu-tag round bg-red sm" style="float: right;">{{msgnum}}</view>
			</view>
		</view>
		<view class=" list" @click="check" v-if="isadmin">
			<view class="cuIcon-check">
				<text>审核帖子</text>
				<view v-if="checknum" class="cu-tag round bg-red sm" style="float: right;">{{checknum}}</view>
			</view>
		</view>
		<view class="list " @click="jb">
			<view class="cuIcon-upload">
				<text>上传举报</text></view>
		</view>
		<view class="list" @click="refer">
			<view class="cuIcon-search">
				<text>举报查询</text>
			</view>

		</view>
		<view class=" list" @click="vip" v-if="!isvip">
			<view class="cuIcon-vip">
				<text>会员充值</text>
			</view>
		</view>
		<view class=" list" @click="admin" v-if="isadmin">
			<view class="cuIcon-settings">
				<text>管理员设置</text>
			</view>
		</view>
		<tabbar></tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				login: false,
				info: {},
				msgnum: "",
				checknum: "",
				isadmin:"",//管理员
				isvip:"",//会员
			};
		},
		async onShow() {
			uni.showLoading()
			this.login = uni.getStorageSync('islogin')
			if (this.login) { //登录了
				let info = uni.getStorageSync('userPhone') || uni.getStorageSync('userWx');
				this.info = info
				let res  = await uniCloud.callFunction({
					name:"admin",
					data:{
						type:"checkadmin",
						id:info.id
					}
				}) 
				console.log(res);
				this.isadmin = res.result.data[0].admin
				//res.result.data[0].admin
				this.isvip = res.result.data[0].vip
				await this.$store.dispatch('initmsgnum', info.id) //获取消息通知数量
				await this.$store.dispatch('initchecknum') //获取审核帖子数量
				this.msgnum = this.$store.state.msg.length
				this.checknum = this.$store.state.checknum.result.affectedDocs
				this.$store.commit('initnum',parseInt(this.msgnum) + this.isadmin ? parseInt(this.checknum) :0	 )
			}
			uni.hideLoading()
		},
		methods: {
			jb() {
				uni.navigateTo({
					url: "../jubao/jubao"
				})
			},
			refer() {
				uni.navigateTo({
					url: `../refer/refer?vip=${this.isvip}`
				});
			},
			check() {
				uni.navigateTo({
					url: '../check/check'
				});
			},
			gologin() {
				uni.navigateTo({
					url: '../login/login'
				})
			},
			vip() {
				uni.navigateTo({
					url: '../vip/vip'
				})
			},
			message() {
				uni.navigateTo({
					url: '../message/message'
				})
			},
			admin() {
				uni.navigateTo({
					url: "../admin/admin"
				})
			}
		}
	}
</script>

<style lang="scss">
	.padding text {
		margin-left: 4%;
		align-content: center;
	}


	.list {
		background-color: #FFFFFF;
		margin-top: 2%;
		padding: 40upx;

		text {
			margin-left: 2%;
		}
	}

	.listcard-header_image {
		flex-shrink: 0;
		width: 60upx;
		height: 60upx;
		border-radius: 50%;
		overflow: hidden;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>
